package com.dy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dy.entity.Cinema;
import com.dy.entity.Order;
import com.dy.mapper.CinemaMapper;
import com.dy.mapper.OrderMapper;
import com.dy.service.IFeignOrderService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Auther: dy
 * @Date: 2022/4/16 - 04 - 16 - 18:57
 * @Description: com.dy.service.impl
 * @version: 1.0
 */
@Service
public class QueueService {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private CinemaMapper cinemaMapper;
    @Autowired
    private IFeignOrderService feignOrderService;

    @RabbitListener(queues = "orderQueue")
    public void getOrder(Order order){
        System.out.println(order);
        QueryWrapper<Cinema> wrapper = new QueryWrapper<>();
        wrapper.eq("cinema_name",order.getCinameName());
        Cinema cinema = cinemaMapper.selectOne(wrapper);
        cinema.setCinemaNum(cinema.getCinemaNum()-order.getOrderNumber());
        cinemaMapper.update(cinema,wrapper);
        if (orderMapper.insert(order) > 0 ? true : false){
            feignOrderService.updateOrderState(order.getOrderSerial());
        }
    }
}
